//
//  GuideViewController.swift
//  NeuFood
//
//  Created by yangjingxin on 2017/9/20.
//  Copyright © 2017年 yangjingxin. All rights reserved.
//

import UIKit

class GuideViewController: UIViewController, UIScrollViewDelegate {
    
    var numOfPages = 4
    
    override func viewDidLoad() {
        
        let frame = self.view.bounds
        //scrollVIew的初始化
        let scrollView=UIScrollView()
        scrollView.frame=self.view.bounds
        scrollView.delegate = self
        //为了能让内容横向滚动，设置横向内容宽度为3个页面的宽度总和
        scrollView.contentSize=CGSize(width: frame.size.width*CGFloat(numOfPages),height: frame.size.height)
        
        scrollView.isPagingEnabled=true
        scrollView.showsVerticalScrollIndicator=false
        scrollView.showsHorizontalScrollIndicator=false
        scrollView.scrollsToTop=false
        
        
        for i in  0..<numOfPages{
            let imgfile = "jianjie\(Int(i+1)).png"
            print(imgfile)
            let image = UIImage(named:"\(imgfile)")
            let imgView = UIImageView(image: image)
            imgView.frame=CGRect(x: frame.size.width*CGFloat(i),y: CGFloat(0),width: frame.size.width,height: frame.size.height)
            scrollView.addSubview(imgView)
        }
        scrollView.contentOffset = CGPoint.zero
        self.view.addSubview(scrollView)
        
        //super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        print("scrolled:\(scrollView.contentOffset)")
        let thirdh = CGFloat(numOfPages-1)*self.view.bounds.size.width
        if(scrollView.contentOffset.x > thirdh)
        {
            let mainStroyboard = UIStoryboard(name:"Main",bundle:nil)
            let viewController: ViewController = mainStroyboard.instantiateViewController(withIdentifier: "mainstroyboard")as! ViewController
            self.present(viewController, animated: true, completion:nil)
            
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destinationViewController.
     // Pass the selected object to the new view controller.
     }
     */
    
}
